﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace DotNet.Utilities
{
    public class IPHelp
    {
        public static string GetLocalHostName()
        {
            //IPGlobalProperties.GetIPGlobalProperties().DomainName +"." + IPGlobalProperties.GetIPGlobalProperties().HostName
            return Dns.GetHostEntry("localhost").HostName;
        }

        public static string GetHostName(IPEndPoint HostAddress, string LocalHostName)
        {
            try
            {
                if (HostAddress.Address.Address == 0)//ToString() == "0.0.0.0")
                {
                    if (HostAddress.Port > 0)
                        return LocalHostName + ":" + HostAddress.Port.ToString();
                    else
                        return "Anyone";
                }
                return Dns.GetHostEntry(HostAddress.Address).HostName + ":" + HostAddress.Port.ToString();
            }
            catch
            {
                return HostAddress.ToString();
            }
        }
    }
}
